package com.un.ebs.customer.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.un.ebs.customer.domain.Defunct;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.un.ebs.customer.domain.DefunctExt;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author liubo
 * @since 2019-09-24
 */

@Component
public interface DefunctMapper extends BaseMapper<Defunct> {

    @SqlParser(filter = true)
    @Select("select * from tb_defunct where id=#{id}")
    Defunct selectNotTenantById(@Param("id") String id);

    /**
     * 查询墓位使用者的纪念日
     * @return
     */
    @SqlParser(filter = true)
    @Select("SELECT * FROM v_defunct_ext WHERE (RIGHT(CONVERT(VARCHAR(10), birthday,112),4)=RIGHT(CONVERT(VARCHAR(10), DATEADD(DAY,#{nextDay},GETDATE()),112),4) OR RIGHT(CONVERT(VARCHAR(10), defunct_date,112),4)=RIGHT(CONVERT(VARCHAR(10), DATEADD(DAY,#{nextDay},GETDATE()),112),4))")
    List<DefunctExt> selectByAnniversaries(@Param("nextDay") int nextDay);
}
